<template>
	<view>
		<view v-for="(data,index) in res" :key="index">
		   <view style="background: #fff;margin-bottom: 20upx;"> 
				<view class="goods">
					<view class="top webkit">
						<view class="flex" v-cloak>订单号：{{data.ordersn}}</view>
						<text v-if="data.status == -1">已取消</text>
						<text v-if="data.status == 0">待付款</text>
						<text v-if="data.status == 1">待发货</text>
						<text v-if="data.status == 2">待收货</text>
						<text v-if="data.status == 3">已完成</text>
					</view>
					<view v-for="(item1,i1) in data.goods" :key="i1">
						<block v-for='(item,i) in item1.goods' :key = 'i'>
							<view class="center webkit">
								<image :src="item.thumb" mode=""></image>
								<view class="flex" v-cloak>{{item.title}}</view>
								<view>
									<text v-cloak>¥{{item.price}}</text>
									<text style="color: #999;" v-cloak>x{{item.total}}</text>
								</view>
							</view>
						</block>
					</view>
					<view class="bottom" v-cloak>
						共{{data.goods_num}}件商品 实付:<text v-cloak>{{data.zzzf}}</text>
					</view>
				</view>
				<view class="status webkit">
					<view class="flex"></view>
					<button type="primary" @click="del(data.id)">彻底删除订单</button>
					<button type="primary" v-if="data.status != -1" @click="huifu(data.id)">恢复订单</button>
				</view>
			 </view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				res:[],
				openid:''
			};
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		methods:{
			huifu(id){
				uni.showModal({
					content: '确认要恢复该订单吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading()
							uni.request({
								url: 'http://hszj.hongshantang696.com//app/index.php?i=5&c=entry&m=ewei_shopv2&do=mobile&r=order.op.delete&app=1&orderid='+id+'&userdeleted=0',
								method: 'POST',
								data: {'openid':this.openid},
								header: {'Content-Type': 'application/x-www-form-urlencoded'},
								success: res => {
									this.setAjax()
								},
								fail: () => {},
								complete: () => {}
							});
						}
					}
				})
			},
			del(id){
				uni.showModal({
					content: '确认要彻底删除该订单吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading()
							uni.request({
								url: 'http://hszj.hongshantang696.com//app/index.php?i=5&c=entry&m=ewei_shopv2&do=mobile&r=order.op.delete&app=1&orderid='+id+'&userdeleted=2',
								method: 'POST',
								data: {'openid':this.openid},
								header: {'Content-Type': 'application/x-www-form-urlencoded'},
								success: res => {
									this.setAjax()
								},
								fail: () => {},
								complete: () => {}
							});
						}
					}
				})
			},
			setAjax(){
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=5&c=entry&m=ewei_shopv2&do=mobile&r=order.get_list&app=1&page=1&status=5',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						uni.hideLoading()
						this.res = res.data.result.list
					},
					fail: () => {},
					complete: () => {}
				});
					
			}
		}
	}
</script>

<style>.goods{padding-bottom:10upx;border-bottom:1px solid #f0f0f0;}.goods .top{padding:16upx 20upx;border-bottom:1px solid #f0f0f0;margin-bottom:10upx;}.goods .top .flex{font-size:26upx;}.goods .top text{color:#666;font-size:26upx;}.goods .center{padding:16upx 30upx;}.goods .center image{width:160upx;height:160upx;margin-right:20upx;}.goods .center view{}.goods .center .flex{margin-right:20upx;}.goods .center text{display:block;text-align:right;font-size:26upx;}.goods .bottom{font-size:24upx;text-align:right;padding:10upx 30upx;}.goods .bottom text{font-size:26upx;color:#f55;}.status{padding:20upx;}.status button{height:56upx;font-size:24upx;line-height:56upx;margin:0;margin-left:20upx;border-radius:56upx;}.status button:after{display:none;}</style>
